load("@rules_cc//cc:cc_library.bzl", "cc_library")

cc_library(
    name = "popt",
    srcs = [
        "src/popt.c",
        "src/poptconfig.c",
        "src/popthelp.c",
        "src/poptint.c",
        "src/poptint.h",
        "src/poptparse.c",
        "src/system.h",
    ],
    hdrs = [
        "src/popt.h",
    ],
    copts = [
        "-Wall",
    ],
    includes = [
        "src",
    ],
    linkopts = select({
        "@platforms//os:macos": ["-liconv"],
        "//conditions:default": [],
    }) + [
        # "-Wl,--no-undefined",
        # "-Wl,--version-script,\"$(execpath src/libpopt.vers)\"",
    ],
    local_defines = [
        "HAVE_FNMATCH_H",
        "HAVE_GETEUID",
        "HAVE_GETUID",
        "HAVE_GLOB_H",
        "HAVE_ICONV",
        "HAVE_LANGINFO_H",
        "HAVE_MBSRTOWCS",
        "HAVE_SETREUID",
        "HAVE_SETUID",
        "HAVE_SRANDOM",
        "HAVE_STDALIGN_H",
        "HAVE_STPCPY",
        "HAVE_STRERROR",
        "HAVE_VASPRINTF",
        "PACKAGE=\\\"popt\\\"",
        "POPT_SYSCONFDIR=\\\"/usr/local/etc\\\"",
        "popt_EXPORTS",
    ],
    textual_hdrs = [
        "src/lookup3.c",
        "src/poptint.h",
        "src/system.h",
    ],
    visibility = ["//visibility:public"],
)

alias(
    name = "libpopt",
    actual = ":popt",
    visibility = ["//visibility:public"],
)
